package mysql

import "gorm.io/gorm"

type Good struct {
	gorm.Model
	UserId     int     `gorm:"type:int;not null;comment:'用户Id'"`
	GoodsTitle string  `gorm:"type:varchar(50);not null;comment:'商品标题'"`
	GoodsStock int     `gorm:"type:int;not null;comment:'商品库存'"`
	GoodsCover string  `gorm:"type:varchar(255);not null;comment:'商品图片'"`
	GoodsPrice float64 `gorm:"type:double(10,2);not null;comment:'商品价格'"`
}

func (g *Good) GetGood(id int) error {
	return DB.Where("id = ?", id).Limit(1).Find(&g).Error
}

func (g *Good) UpdateStock(stock int) error {
	return DB.Model(&g).Update("goods_stock", stock).Error
}
